package com.huwei.activemq.controller;

import cn.hutool.json.JSONObject;
import com.huwei.activemq.entity.MsgEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 胡伟
 * @Date: 2021/1/13 18:10
 * @Description:
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendSynMsg")
    public String sendSynMsg(@RequestParam("msg") String msg) {
        MsgEntity msgEntity = new MsgEntity();
        msgEntity.setMsg(msg);
        msgEntity.setSendUser("admin");
        //需要发送的交换机，指定的键值，和消息内容,因为我们配置了交换机为jiahong,指定的键值为xiaojiang
        rabbitTemplate.convertAndSend("jiahong","xiaojiang",msgEntity);
        return "success";
    }


}
